package com.pro.controller;

import com.pro.pojo.JsUserOrder;
import com.pro.pojo.JsonData;
import com.pro.service.JsUserOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * ClassName:JsUserOrderController
 * Package:com.pro.controller
 * Description: 商品订单列表
 *
 * @Date:2021/11/8 上午 10:50
 * @Author: WYH
 */
@Controller
@RequestMapping("/order")
public class JsUserOrderController {

    @Autowired
    private JsUserOrderService jsUserOrderService;

    /**
     * @author WYH
     * @date 2021/11/10 上午 10:50
     * @content : 查询订单列表所有数据
     */
    @RequestMapping("/getAllorder")
    @ResponseBody
    public JsonData getAllorder(String orderPaymentChannel, String orderSource,String orderStatus) {
        orderPaymentChannel = orderPaymentChannel != null  ? "%"+orderPaymentChannel+"%":"%%";
        orderSource = orderSource != null  ? "%"+orderSource+"%":"%%";
        orderStatus = orderStatus != null  ? "%"+orderStatus+"%":"%%";

        List<JsUserOrder> allorder = jsUserOrderService.getAllorder(orderPaymentChannel,orderSource,orderStatus);
        int count = jsUserOrderService.count(orderPaymentChannel,orderSource,orderStatus);
        return allorder!= null ? JsonData.buildSuccess(allorder,count):JsonData.buildError("服务端错误");
    }

    /**
     * @author WYH
     * @date 2021/11/10 上午 10:50
     * @content : 删除订单列表数据
     */
    @RequestMapping("/delOrder")
    @ResponseBody
    public JsonData delOrder(Integer orderId) {
        Boolean aBoolean = jsUserOrderService.delOrder(orderId);
        return aBoolean != false ? JsonData.buildSuccess(aBoolean) :JsonData.buildError("服务端错误");
    }
    /**
     *
     * @author ZPT
     * @date 2021/12/7 19:49
     * @content :各个状态的数量
     */
    @RequestMapping("/statusCount")
    @ResponseBody
    public JsonData statusCount(String orderStatus){
        int statusCount = jsUserOrderService.statusCount(orderStatus);
        return statusCount>=0?JsonData.buildSuccess(statusCount):JsonData.buildError("服务端错误");
    }
}
